package mw.live;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.net.URL;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.WindowConstants;
import javax.swing.UIManager.LookAndFeelInfo;

public class LiveClientGUI extends JFrame {
	private static final long serialVersionUID = 1L;
	private JTextField clientPort = new JTextField();
	private JLabel clientPortLabel = new JLabel();
	private JTextField clientIP = new JTextField();
	private JLabel clientIPLabel = new JLabel();
	private JButton joinServer = new JButton();

	public LiveClientGUI(String title) {
       	super(title);
       	
		try {
		    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
		        if ("Nimbus".equals(info.getName())) {
		            //UIManager.setLookAndFeel(info.getClassName());
		            break;
		        }
		    }
		} catch (Exception e) {
		}
		
		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		int frameWidth = 300;
		int frameHeight = 115;
		setSize(frameWidth, frameHeight);
		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
		int x = (d.width - getSize().width) / 2;
		int y = (d.height - getSize().height) / 2 ;
		setLocation(x, y);
		Container cp = getContentPane();
		cp.setLayout(null);
		
        try {
        	setIconImage(new ImageIcon(getClass().getResource("/icons/comments.png")).getImage());
        } catch (Exception e) {
            e.printStackTrace();
        }
		
		clientPortLabel.setBounds(0, 0, frameWidth, 16);
		clientPortLabel.setText("Port:");
		clientPortLabel.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
		cp.add(clientPortLabel);
		clientPort.setBounds(0, 16, frameWidth, 16);
		clientPort.setText("12345");
		cp.add(clientPort);
		clientIPLabel.setBounds(0, 32, frameWidth, 16);
		clientIPLabel.setText("ServerIP:");
		clientIPLabel.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
		cp.add(clientIPLabel);
		clientIP.setBounds(0, 48, frameWidth, 16);
		clientIP.setText("localhost");
		cp.add(clientIP);
		joinServer.setBounds(0, 64, frameWidth, 25);
		joinServer.setText("join Server");
		cp.add(joinServer);
		joinServer.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				joinServer(evt);
			}
		});

		setResizable(false);
		setVisible(true);
	}

	public void joinServer(ActionEvent evt) {
		LiveClient.impMain(this.clientIP.getText(),Integer.parseInt(this.clientPort.getText()));
		setVisible(false);
	}

	public static void main(String[] args) {
		new LiveClientGUI("MW Live");
	}
}

